package bb.lanxing


import bb.lanxing.lib.devices.sgsettingentity.routebook.Routebooks
import com.blankj.utilcode.util.GsonUtils
import org.json.JSONArray
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Test

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class KotlinUnitTest {
    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }

    @Test
    fun arrayTest() {
        array(arrayOf("1", "2", "3"))
    }


    private fun array(args: Array<String>) {
        for (i in args) {
            println("array i = $i")
        }
    }


    @Test
    fun nullTest() {
        val array = listOf<CharSequence?>(null, "1", "2", null)
        array.forEach { item ->
            val test = item?.toString()
            println("test = $test")
        }
    }

    @Test
    fun listTest() {
        val list = listOf(1, 2, 3)
        println("listTest = ${list.toString()}")
        val sb = StringBuilder()
        list.forEach { item ->
            sb.append(item).append(",")
        }
        println("listTest = ${sb.toString()}")
        val str = sb.trim { it -> it == ',' }
        println("listTest = $str")
    }

    @Test
    fun gsonTest() {
        val json = JSONObject()
        json.put("version", "2.20")
        json.put("device_model", "Lanxing")
        json.put("sn", "123456")
        json.put("update_at", System.currentTimeMillis() / 1000)
        json.put("routes", JSONArray())
        val readText = json.toString()
        val result = GsonUtils.fromJson(readText, Routebooks::class.java)
        println("result = $result")
    }

    @Test
    fun classTest() {
        val start = Greeting()
        println("classTest")
        val start2 = Greeting()
        println("classTest")

    }
}